##
#   Project: BlueDUN
#            Internet connection manager for bluetooth devices.
#    Author: Fabio Castelli <muflone@vbsimple.net>
# Copyright: 2009 Fabio Castelli
#   License: GPL-2+
#  This program is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by the Free
#  Software Foundation; either version 2 of the License, or (at your option)
#  any later version.
# 
#  This program is distributed in the hope that it will be useful, but WITHOUT
#  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
#  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
#  more details.
# 
# On Debian GNU/Linux systems, the full text of the GNU General Public License
# can be found in the file /usr/share/common-licenses/GPL-2.
##

import gtk
import gtk.glade
import handlepaths
import gettext
import string
from gettext import gettext as _

# Load domain for translation
for module in (gettext, gtk.glade):
  module.bindtextdomain(handlepaths.APP_NAME, handlepaths.getPath('locale'))
  module.textdomain(handlepaths.APP_NAME)

def showWindow():
  "Show new connection dialog"
  gladeFile = gtk.glade.XML(
    fname=handlepaths.getPath('ui', 'newconnection.glade'),
    domain=handlepaths.APP_NAME)
  gw = gladeFile.get_widget

  dialogNewConnection = gw('dialogNewConnection')
  dialogNewConnection.set_icon_from_file(handlepaths.get_app_logo())
  dialogNewConnection.set_title(_('Create new connection'))
  txtConnectionName = gw('txtConnectionName')
  txtConnectionName.set_activates_default(True)

  # Repeat until a valid name is selected
  while True:
    connection_name = ''
    if dialogNewConnection.run() != gtk.RESPONSE_OK:
      break
    connection_name = txtConnectionName.get_text()
    valid_chars = '%s%s-_' % (string.letters, string.digits)
    if len(connection_name) > 0 and \
      len([l for l in connection_name if l not in valid_chars]) == 0:
      break
  dialogNewConnection.destroy()
  return connection_name
